package v3.chapter3.waitReleaseLock;

public class Run {

	public static void main(String[] args) {
		Object lock=new Object();
		ThreadA a=new ThreadA(lock);
		a.start();
		ThreadB b=new ThreadB(lock);
		b.start();
	}

}


class ThreadA extends Thread{
	private Object lock;
	public ThreadA(Object lock) {
		super();
		this.lock=lock;
	}
	
	@Override
	public void run() {
		Service service=new Service();
		service.testMethod(lock);
	}
}

class ThreadB extends Thread{
	private Object lock;
	public ThreadB(Object lock) {
		super();
		this.lock=lock;
	}
	
	@Override
	public void run() {
		Service service=new Service();
		service.testMethod(lock);
	}
}

class Service{
	public void testMethod(Object lock) {
		try {
			synchronized(lock) {
				System.out.println("begin wait()");
			    lock.wait();
				//Thread.sleep(4000);
				System.out.println(" end wait()");
			}
		}catch(InterruptedException e) {
			e.printStackTrace();
		}
	}
}